﻿using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Event.UI;
using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.DisplayApp
{
    /// <summary>
    /// SettingView.xaml 的交互逻辑
    /// </summary>
    public partial class SettingView : View
    {
        private Window _mainWindow;

        public SettingView(Window mainWindow)
        {
            InitializeComponent();

            _mainWindow = mainWindow;

            this.DataContext = UIContext.Current;
        }

        /// <summary>
        /// 刷新显示网络状态
        /// </summary>
        /// <param name="isConnected">是否处于连接状态</param>
        /// <param name="clientProxyState"></param>
        public void RefreshNetState(bool isConnected, Coolzon.Event.UI.UINetConnectionStateFeedbackEvent.NetConnectionState[] clientProxyState)
        {
            if (isConnected)
            {
                _ctlTextNetState.Text = "已连接";
            }
            else
            {
                _ctlTextNetState.Text = "已断开";
            }
            dataGridProxyState.ItemsSource = null;
            dataGridProxyState.ItemsSource = clientProxyState;
        }

        private void btn_UnderControl_Click(object sender, RoutedEventArgs e)
        {
            NCLChangeControlStateEvent @event = new NCLChangeControlStateEvent();
            @event.ControlState = Service.Contract.ControlState.UnderControl;
            NCLEventBus.Publish(@event);
        }

        private void btn_OutofControl_Click(object sender, RoutedEventArgs e)
        {
            NCLChangeControlStateEvent @event = new NCLChangeControlStateEvent();
            @event.ControlState = Service.Contract.ControlState.OutOfControl;
            NCLEventBus.Publish(@event);
        }

        private void btn_BeginAutoPlay_Click(object sender, RoutedEventArgs e)
        {
            UIEventBus.Publish(new UIAutoPlayEvent(true));
            //CloseSetingView();
        }

        private void btn_StopAutoPlay_Click(object sender, RoutedEventArgs e)
        {
            UIEventBus.Publish(new UIAutoPlayEvent(false));
            //CloseSetingView();
        }

        private void btn_BeginFullScreen_Click(object sender, RoutedEventArgs e)
        {
            UIEventBus.Publish(new UIChangeFullScreenStateEvent());
        }

        private void btn_StopFullScreen_Click(object sender, RoutedEventArgs e)
        {
            UIEventBus.Publish(new UIChangeFullScreenStateEvent());
        }

        private void btn_Quit_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown(); 
        }

        protected override void OnActive()
        {
            Common.EventBus.Instance.Register(this);
            base.OnActive();
        }

        protected override void OnDeactive()
        {
            Common.EventBus.Instance.Unregister(this);
            base.OnDeactive();
        }
    }

    public class BackgroundConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool IsConnected = (bool)value;
            if (IsConnected)
            {
                return new SolidColorBrush(Colors.LightBlue);
            }
            else
            {
                return new SolidColorBrush(Colors.AliceBlue);
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
